/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package network.packets;

import utils.StringUtils;
import utils.Utils;
/**
 *
 * @author Kvest
 */
public class PPCSettingsResponce extends Packet
{
    private int T1,T2,T3;
    private String javaVersion;
    private String link;
    private int maxOrdersCount;
    private int autoTariffClassUID;
    
    public PPCSettingsResponce(byte[] data)
    {
        super(PPCSETTINGS_RESPONCE);
        T1 = 60000;
        T2 = 60000;
        T3 = 60000;
        javaVersion = "";
        link = "";
        maxOrdersCount = -1;
        autoTariffClassUID = 0;

        parse(data);
    }

    protected void parse(byte[] data)
    {
        int offset = 0;

        //Пропускаем название пакета
        byte[] buffer4 = new byte[4];
        System.arraycopy(data, offset, buffer4, 0, buffer4.length);
        offset += buffer4.length + Utils.byteToInt(buffer4);
        
        //MinSendCoordsTime,MaxSendCoordsTime,SendCoordsPerDistance,RegisterDriversTimeOut (все int)
        offset += (4 * 4);
        
        //T1
        System.arraycopy(data, offset, buffer4, 0, buffer4.length);
        offset += buffer4.length;
        T1 = Utils.byteToInt(buffer4);
  
        //T2
        System.arraycopy(data, offset, buffer4, 0, buffer4.length);
        offset += buffer4.length;
        T2 = Utils.byteToInt(buffer4);
        //T3
        System.arraycopy(data, offset, buffer4, 0, buffer4.length);
        offset += buffer4.length;
        T3 = Utils.byteToInt(buffer4);

        int strSize;
        byte[] buffer;
        try
        {
            //AutoTariffClassUID
            System.arraycopy(data, offset, buffer4, 0, buffer4.length);
            offset += buffer4.length;
            autoTariffClassUID = Utils.byteToInt(buffer4);

            //JavaVersion
            System.arraycopy(data, offset, buffer4, 0, buffer4.length);
            offset += buffer4.length;
            strSize = Utils.byteToInt(buffer4);
            buffer = new byte[strSize];
            System.arraycopy(data, offset, buffer, 0, buffer.length);
            offset += buffer.length;
            javaVersion = StringUtils.bytesToStr(buffer);
            
            // Линк на новую версию Java
            System.arraycopy(data, offset, buffer4, 0, buffer4.length);
            offset += buffer4.length;
            strSize = Utils.byteToInt(buffer4);
            buffer = new byte[strSize];
            System.arraycopy(data, offset, buffer, 0, buffer.length);
            offset += buffer.length;
            link = StringUtils.bytesToStr(buffer);
            
            //Кол-во одновременно взятых заказов
            System.arraycopy(data, offset, buffer4, 0, buffer4.length);
            offset += buffer4.length;
            maxOrdersCount = Utils.byteToInt(buffer4);
        }catch(Exception e){}
        
        buffer = null;
        buffer4 = null;
    }

    public int getT1()
    {
        return T1;
    }

    public int getT2()
    {
        return T2;
    }

    public int getT3()
    {
        return T3;
    }

    public String getJavaVersion()
    {
        return javaVersion;
    }

    public String getLink()
    {
        return link;
    }

    public int getMaxOrdersCount()
    {
        return maxOrdersCount;
    }

    public int getAutoTariffClassUID() 
    {
        return autoTariffClassUID;
    }
}
